home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / csrc1.arc / ESP.C < prev    next >
C/C++ Source or Header  |  1989-07-27  |  1KB  |  95 lines

  1.  
  2. /*
  3.  * esp.  Outputs to a special purpose paper tape punch
  4.  *    (for loading eprom's?)
  5.  */
  6.  
  7. #include <stdio.h>
  8.  
  9. #define    FF    0377
  10.  
  11. FILE *esb;
  12. FILE *pun;
  13.  
  14. main(argc, argv)
  15. char *argv[];
  16. {
  17.     register int b, n;
  18.  
  19.     if(argc < 2) {
  20.         fprintf(stderr, "Usage: esp file.\n");
  21.         exit(1);
  22.     }
  23.     if((esb=fopen(argv[1], "r")) == NULL) {
  24.         fprintf(stderr, "%s: cannot open.\n", argv[1]);
  25.         exit(1);
  26.     }
  27.     if((pun=fopen("pp0:", "wn")) == NULL) {
  28.         fprintf(stderr, "Who stole the punch.\n");
  29.         exit(1);
  30.     }
  31.     while((b=get()) != EOF) {
  32.         n = 8;
  33.         do {
  34.             putc(0, pun);
  35.         } while(--n);
  36.         putc(FF, pun);
  37.         putc(b, pun);
  38.         copy();
  39.         n = get();
  40.         putc(n, pun);
  41.         while(n--)
  42.             copy();
  43.         copy();
  44.         copy();
  45.     }
  46.     n = 8;
  47.     do {
  48.         putc(0, pun);
  49.     } while(--n);
  50.     putc(FF, pun);
  51.     putc(FF, pun);
  52. }
  53.  
  54. copy()
  55. {
  56.     register int b;
  57.  
  58.     if((b=get()) == EOF)
  59.         botch("copy");
  60.     putc(b, pun);
  61. }
  62.  
  63. get()
  64. {
  65.     register int c1, c2;
  66.  
  67.     while((c1=getc(esb))==' ' || c1=='\n')
  68.         ;
  69.     if(c1 == EOF)
  70.         return(EOF);
  71.     while((c2=getc(esb))==' ' || c2=='\n')
  72.         ;
  73.     if(c2 == EOF)
  74.         botch("get");
  75.     return(val(c1)<<4 | val(c2));
  76. }
  77.  
  78. val(c)
  79. {
  80.     if(c>='0' && c<='9')
  81.         return(c-'0');
  82.     if(c>='a' && c<='f')
  83.         return(10+c-'a');
  84.     if(c>='A' && c<='F')
  85.         return(10+c-'A');
  86.     botch("val");
  87. }
  88.  
  89. botch(s)
  90. char *s;
  91. {
  92.     fprintf(stderr, "Botch in %s\n", s);
  93.     exit(1);
  94. }
  95.